package com.liupf;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.liupf.common.utils.SmsUtil;
import com.liupf.controller.OrderController;

public class OrderRunnable implements Runnable{

	//private boolean Flag2or3=true;//2分钟
	private  String name=null;
	private  int orderId=0;
	private  double dis=0;
	private  String whereStr="";
	private String mode="";
	private int times=0;
	private String driver;
	
	
	public final static String GRAB_MODE="0";//抢单
	public final static String FORCE_MODE="1";//强制派单
	

	//mode 模式 0：员工抢单，1强制派单    times次数从1开始
	public OrderRunnable(String name,int orderId,double dis,String whereStr,String mode,int times,String driver){
		this.name=name;
		this.orderId=orderId;
		this.dis=dis;
		this.whereStr=whereStr;
		//this.Flag2or3=Flag2or3;
		this.mode=mode;
		this.times=times;
		this.driver=driver;
	}

	
	public void run()
	{
		try {
				/*if(Flag2or3)
				{
					Thread.sleep(30*1000);
					OrderController.myAssignment2(orderId, dis, whereStr);
				}
				else
				{//返回人工派单
					Thread.sleep(1*60*1000);
					OrderController.myAssignment3(orderId);
				}*/
			
				if(GRAB_MODE.equals(mode)){
					if(times==1 || times==2){
						//第一次,第二次 同公司抢
						Thread.sleep(50*1000);
						OrderController.myAssignment2(orderId, dis, whereStr,true,times,mode);
					}else if(times==3|| times==4){
						//第3,4次 ，不同公司抢
						Thread.sleep(50*1000);
						OrderController.myAssignment2(orderId, dis, whereStr,false,times,mode);
					}else{
						//第五次 就返回订单池
						Thread.sleep(1*60*1000);
						OrderController.myAssignment3(orderId);
					}
				}else{
					//强制派单，第一次在外面做了，所以都从第2次开始
					if(times==2 ){
						//第2,3次 同公司抢
						Thread.sleep(50*1000);
						OrderController.my(driver, orderId, times);
					}/*else if(times==4| times==5){
						//第4,5次 ，不同公司抢
						//Thread.sleep(50*1000);
						//OrderController.myAssignment2(orderId, dis, whereStr,false,times,mode);
					}*/else{
						//第四次 返回订单池
						Thread.sleep(1*60*1000);
						OrderController.myAssignment3(orderId);
					}
				}
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	

	
}
